/*ParallelPlatform Project - A web platform to distribute and share knowledge
Copyright (C) 2011  Daniel Guerrero Martinez & Sergio Rodriguez Lumley

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.*/

$(document).ready(function(){
	// Change the behavior of 'edit' button
	$('a[href$="/edit/"]').click(function(event) {
		event.preventDefault();
		loaderAloha(function(){
			$('#title').aloha();
			$('#content').aloha();
			GENTICS.Aloha.Save.url="./ajax/edit/"
		});
		
		$(this).remove();
		
		$.each($('#subpage').find('li'),function(){
			initElement(this);
		});
		
		/* Section to add a button that saves the current state of the list of children pages
		button = jQuery('<input type="button" value="Change" />');$('#subpage').append(button);button.click(function(event){var order = [];
			$.each($('#subpage').find('a'),function(){var len = $(this).attr('href').length;order.push( $(this).attr('href').substring(1,len-1) );});
			$.post("./ajax/changeOrder/", { 'order': order }, function (data) {if( data.success ){alert("OK");}else{alert("Error");}});});*/
	});
	
});

function initElement( li ) {  
  	li = $(li);
  	up = jQuery('<div class="BtnUp"><span>Up</span></div>')
  	down = jQuery('<div class="BtnDown"><span>Down</span></div>')
  	li.prepend(down)
  	li.prepend(up)
  	up.click(function(event){
  		li.insertBefore(li.prev())
  	});
  	down.click(function(event){
  		li.insertAfter(li.next())
  	});
  	
  	li.find("a").each(function(){
  		$(this).attr('nohref', $(this).attr('href'));
  		$(this).removeAttr('href');
  	});
}


